package com.example.ykbboom.universitytransportation.Activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.example.ykbboom.universitytransportation.Interface.InitMethod;
import com.example.ykbboom.universitytransportation.Util.SharedPrefUtil;

public class BaseActivity extends AppCompatActivity implements View.OnClickListener,InitMethod {


    public static final String SMSSDK_APP_KEY = "1b06311d6011d";
    public static final String SMSSDK_APP_SECRET = "edd0c628a00fa48f1b05ed0a85f8fb0b";
    private ForceOffLineReceiver forceOffLineReceiver = new ForceOffLineReceiver();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityManager.addActivity(this);
    }

    /**
     * 初始化广播接收器 注册
     */
    @Override
    protected void onResume() {
        super.onResume();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.example.ykbboom.FORCE_OFFLINE");
        registerReceiver(forceOffLineReceiver, intentFilter);//广播接收器注册
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ActivityManager.removeActivity(this);
        unregisterReceiver(forceOffLineReceiver);
    }

    class ForceOffLineReceiver extends BroadcastReceiver {

        @Override
        public void onReceive(final Context context, Intent intent) {

            SharedPrefUtil.saveLoginState(false);
            SharedPrefUtil.saveDriverState(false);
            SharedPrefUtil.saveCheckDistance(3000);

            ActivityManager.finishAll();//销毁所有活动
            Intent intent1 = new Intent(context, LoginActivity.class);
            context.startActivity(intent1);


        }
    }
        @Override
        public void onClick(View v) {

        }

        @Override
        public void initView() {

        }

    }

